package com.mx.web.controller;

import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mx.web.model.ResInfo;
import com.mx.web.model.User;
import com.mx.web.service.UserService;

@RequestMapping("/user")
@Controller
public class UserController {

	private static final Logger logger = LoggerFactory.getLogger(UserController.class);
	
	@Autowired
	private UserService userService;
	ResInfo resInfo = new ResInfo();

	@ResponseBody
	@RequestMapping(value = "/register", method = RequestMethod.POST)
	public String register(HttpSession session, User user) {
		user = userService.register(user);
		session.setAttribute("user", user);
		return "index";
	}

	@RequestMapping(value = "/signin", method = RequestMethod.POST)
	public String signin(HttpSession session, User user) {
		logger.info("进入signin()...");
		user = userService.signin(user);
		if (user != null) {
			session.setAttribute("user", user);
			return "back/index";
		}
		return "index";
	}

}